<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    ul{
        height: 500px;
        overflow: auto;
        width: 800px;
        margin: 0 auto;
        background: pink;  
    }
    ul li{
            line-height: 100px;
        }
</style>
<body>
    <ul class="box">
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
        <li>1</li>
    </ul>
</body>
<script>
    // 节流  节省触发的次数

    // 控制高频率执行的次数
 let box = document.querySelector('.box')
 let timer = null
 box.onscroll = function(){
    // 在这段时间内 如果动作又发生了 就无视该动作，忽略一定时间内的所有时间  直到事件执行结束，才能重新触发
    if(timer){
        return  // 不到一秒你开启的滚动，我全部给你return
    }

    timer = setTimeout(() => {
        let color ='#'+ Math.random().toString(16).slice(2,8)
       box.style.background = color
       timer = null
    },1000);
   
 }





</script>
</html>